package com.view;

import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.bluetooth.Dispatcher;
import com.firewarning.R;

public class ShowData extends AppCompatActivity {
    private TextView text;
    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
           if (msg.what==0) {

                    String data = (String)msg.obj;
                    if(data!=null) {
                        text.setText(data);
                    }
            }

        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_data);
        text=(TextView)this.findViewById(R.id.show_data_number);
        Button show=(Button)findViewById(R.id.show_data_button);
        show.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(ShowData.this,"开始显示数据",Toast.LENGTH_SHORT).show();
                Intent intent=ShowData.this.getIntent();
                String address=intent.getExtras().getString("address");
                BluetoothAdapter   bluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
                Dispatcher dispatcher = new Dispatcher(bluetoothAdapter, address);
                dispatcher.acceptMessage(ShowData.this,mHandler);

            }
        });

    }

}
